<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
     <el-form-item label="桌号" prop="tablenumberId">

       <el-select v-model="queryParams.tablenumberId"   filterable   placeholder="请选择请选择桌号">
         <el-option
           v-for="dict in deskList"
           :key="dict.id"
           :label="dict.tablenumberId"
           :value="dict.id"
         ></el-option>
       </el-select>
      </el-form-item>
      <el-form-item label="姓名" prop="memberId">
        <el-select v-model="queryParams.memberId"   filterable   placeholder="请选择请选择会员">
          <el-option
            v-for="dict in memberList"
            :key="dict.id"
            :label="dict.name"
            :value="dict.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="日期" prop="disDay">
        <el-date-picker
          v-model="disDay"
          type="datetimerange"
          value-format="yyyy-MM-dd HH:mm:ss"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
   <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="deskingList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="店铺名称" align="center" prop="shopName" />
      <el-table-column label="店员名称" align="center" prop="staffName" />
      <el-table-column label="会员名称" align="center" prop="memberName" />
      <el-table-column label="场地类型" align="center" prop="roomName" />
      <el-table-column label="桌子状态" align="center" prop="falg" />
      <el-table-column label="暂停状态" align="center" prop="isStop" />
      <el-table-column label="计费方式" align="center" prop="costName" />
      <el-table-column label="桌号" align="center" prop="tableName" />
      <el-table-column label="开桌时间" align="center" prop="openStartTime" width="180" />
     <!-- <el-table-column label="开桌时长" align="center" prop="openTime" />-->
      <el-table-column label="备注" align="center" prop="remark" />
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--                    <el-button-->
<!--                      size="mini"-->
<!--                      type="text"-->
<!--                      icon="el-icon-delete"-->
<!--                      @click="handleDelete(scope.row)"-->
<!--                    >重置桌子</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listDesking, tableList,getDesking, delDesking, restDesking,addDesking, updateDesking, exportDesking } from "@/api/mahjong/desking";
import { listAllTable } from "@/api/mahjong/tablenumber";
import { listAll } from "@/api/mahjong/member";
import {handlerdata} from "@/api/mahjong/utils";

export default {
  name: "Desking",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 开桌情况表格数据
      deskingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 来源字典
      sourceOptions: [],
      deskList:[],
      memberList:[],
      disDay:undefined,
      // 大小字典
      sizeOptions: [],
      // 模式字典
      modeOptions: [],
      integralOptions:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        source: undefined,
        size: undefined,
        mode: undefined,
        integral: undefined,
        deskId: undefined,
        disDay:undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.initSerach();
    this.getDicts("source").then(response => {
      this.sourceOptions = response.data;
    });
    this.getDicts("open_size").then(response => {
      this.sizeOptions = response.data;
    });
    this.getDicts("majong_type").then(response => {
      this.modeOptions = response.data;
    });
  },
  methods: {
    //初始化查询条件
    initSerach(){
      listAllTable().then(response => {
        this.deskList = response.data;
      });
      listAll().then(response => {
        this.memberList = response.data;
      });

    },
    loadintegral(e){
      this.getDicts(e).then(response => {
        this.integralOptions = response.data;
      });
    },
    /** 查询开桌情况列表 */
    getList() {
      this.loading = true;
      tableList(this.queryParams).then(response => {
        this.deskingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });

    },
    // 来源字典翻译
    sourceFormat(row, column) {
      return this.selectDictLabel(this.sourceOptions, row.source);
    },
    // 大小字典翻译
    sizeFormat(row, column) {
      return this.selectDictLabel(this.sizeOptions, row.size);
    },
    // 模式字典翻译
    modeFormat(row, column) {
      return this.selectDictLabel(this.modeOptions, row.mode);
    },
    // 模式字典翻译
    jfFormat(row, column) {
      console.log(row.mode==='america')
      console.log(row.mode==='common')
      console.log(row.mode==='competition')
      console.log(row.mode==='custom_integral')
      if(row.mode==='america'){

        return handlerdata(row.integral, this.americanMahjongOptions);

      }
      if(row.mode==='common'){
        return handlerdata(row.integral, this.ordinaryMahjongOptions);

      } if(row.mode==='competition'){
        return handlerdata(row.integral, this.matchMahjongOptions);

      }
      if(row.mode==='custom_integral'){
        return handlerdata(row.integral, this.customMahjongOptions);
      }


    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        updateTime: undefined,
        updateBy: undefined,
        createTime: undefined,
        createBy: undefined,
        status: "0",
        bak3: undefined,
        bak2: undefined,
        bak1: undefined,
        source: undefined,
        startTime: undefined,
        finishTime: undefined,
        time: undefined,
        size: undefined,
        mode: undefined,
        integral: undefined,
        remark: undefined,
        deskId: undefined,
        id: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      console.log(this.queryParams);
      if(this.disDay){
        this.queryParams.searchStartTime=this.disDay[0]
        this.queryParams.searchEndTime=this.disDay[1]
      }
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.disDay=undefined;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加开桌情况";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDesking(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改开桌情况";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateDesking(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addDesking(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.orderSn
      this.$confirm('是否确认重置开桌情况"', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return restDesking(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("重置成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有开桌情况数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportDesking(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
<style  rel="stylesheet/scss" lang="scss">
  .pagination-container .el-pagination{
    position: static;
    text-align: center;
  }
  .pagination-container{
    height: auto;
  }
</style>
